package cn.biplam.front.template.base;

import cn.biplam.common.paramters.StyleConst;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.HtmlImage;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Border_Style;
import cn.biplam.front.html.base.Const.Window_Event;

/**
 * 表格单元格内的图片按钮
 */
public class TableCellImage {

	private HtmlDiv button;
	private String ID=null;
	private String imageUrl;
	private String btTitle=null;
	private String clickScript;
	private String defaultColor= StyleConst.Title_BackColor;
	boolean inTitle=true;

	/**
	 * 构造方法
	 * @param ID		页面ID
	 * @param imageUrl	按钮图片
	 */
	public TableCellImage(String ID,String imageUrl){
		this(ID,imageUrl,null);
	}

	/**
	 * 创建20x20图片按钮
	 * @param ID          页面ID
	 * @param imageUrl    图片URL
	 * @param btTitle     按钮标题
	 */
	public TableCellImage(String ID, String imageUrl, String btTitle){
		this.ID = ID;
		this.imageUrl = imageUrl;
		this.btTitle = btTitle;
	}
	
	/**
	 *  设置点击事件脚本
	 * @param bindScript 点击事件脚本
	 */
	public void setOnClickScript(String bindScript){
		this.clickScript = bindScript;
	}

	/**
	 * 返回设置好的Html控件
	 * @return	HtmlWindow
	 * @throws ErrorMessage 
	 */
	public HtmlWindow get() throws ErrorMessage{
		this.button=new HtmlDiv(null,"ptb");
		HtmlImage image = new HtmlImage(this.imageUrl,"pi");
		if(!this.inTitle){
			image.setMarginTop("1");
			this.defaultColor="white";
		}
		image.setTitle(this.btTitle);
		image.setBorder("1", Border_Style.Solid, defaultColor);
		image.setID(ID);
		this.button.put(image);
		
		if(this.clickScript!=null){
			this.button.bind(Window_Event.OnClick,clickScript);
			image.bind(Window_Event.OnmouseOver, "tci('"+this.ID+"','"+defaultColor+"');");
		}
		this.button.setLength(20);
		return this.button;
	}

	public boolean isInTitle() {
		return inTitle;
	}

	public void setInTitle(boolean inTitle) {
		this.inTitle = inTitle;
	}
}
